package controller

import (
	"github.com/gogf/gf/v2/util/gconv"
	"golang.org/x/net/context"
	"lot_admin_api/api"
	"lot_admin_api/internal/model"
	"lot_admin_api/internal/service"
)

var HelpDoc = cHelpDoc{}

type cHelpDoc struct{}

// AddHelpDoc  新增帮助文档
func (h *cHelpDoc) AddHelpDoc(ctx context.Context, req *api.AddHelpDocReq) (res *model.LotHelpIdRes, err error) {
	var reqInfo *model.LotHelpDocInfoAndIdRes
	_ = gconv.Scan(req, &reqInfo)
	id, _ := service.HelpDoc().AddHelpDoc(ctx, reqInfo)
	res = &model.LotHelpIdRes{
		Id: id,
	}
	return res, err
}

// EditHelpDoc  编辑帮助文档
func (h *cHelpDoc) EditHelpDoc(ctx context.Context, req *api.EditHelpDocReq) (res *model.LotHelpIdRes, err error) {
	var reqInfo *model.LotHelpDocInfoAndIdRes
	_ = gconv.Scan(req, &reqInfo)
	id, _ := service.HelpDoc().EditHelpDoc(ctx, reqInfo)
	res = &model.LotHelpIdRes{
		Id: id,
	}
	return res, err
}

// DeleteHelpDoc 删除帮助文档
func (h *cHelpDoc) DeleteHelpDoc(ctx context.Context, req *api.DeleteHelpDocReq) (res *model.LotHelpIdRes, err error) {
	id, _ := service.HelpDoc().DeleteHelpDoc(ctx, req.Id)
	res = &model.LotHelpIdRes{
		Id: id,
	}
	return res, err
}

// HelpDocInfo 通过id获取帮助文档的详情
func (h *cHelpDoc) HelpDocInfo(ctx context.Context, req *api.SearchHelpDocInfoReq) (res *model.LotHelpDocInfoAndIdRes, err error) {
	res, _ = service.HelpDoc().SearchHelpDocInfo(ctx, req.Id)
	return res, err
}

// HelpDocList 获取帮助文档列表
func (h *cHelpDoc) HelpDocList(ctx context.Context, req *api.SearchHelpDocListReq) (res *model.HelpDocListRes, err error) {
	var reqInfo *model.SearchHelpDocListReq
	_ = gconv.Scan(req, &reqInfo)
	res, _ = service.HelpDoc().HelpDocList(ctx, reqInfo)
	return res, err
}
